<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch">
      <el-form-item label="成果名称" prop="title">
        <el-input
          v-model="queryParams.title"
          placeholder="请输入成果名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="成果编号" prop="code">
        <el-input
          v-model="queryParams.code"
          placeholder="请输入成果编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="申报人" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入申报人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table
      v-loading="loading"
      :data="applicationList"
      row-key="id"
      border
    >
      <el-table-column label="成果名称" prop="title" />
      <el-table-column label="成果编号" prop="code" />
      <el-table-column label="申报人" prop="name" />
      <el-table-column label="发表时间" align="center" prop="publishedTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.publishedTime, '{y}-{m}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listApplication } from "@/api/application/application";
import { parseTime } from '@/utils/ruoyi';

export default {
  name: "Weather",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 申请表格数据
      applicationList: [],
      // 是否显示搜索条件
      showSearch: true,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: undefined,
        code: undefined,
        title: undefined
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询申请列表 */
    getList() {
      this.loading = true;
      listApplication(this.queryParams).then(response => {
        this.applicationList = response.rows;
        this.total = response.total;
        this.loading = false;
      }).catch(error => {
        console.error('获取数据失败:', error);
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    }
  }
};
</script>

<style scoped>
.app-container {
  padding: 20px;
}
</style>
